For the data in your question:
select t.*
from table t join
(select trackid, min(case when actid = 21 then id end) as id21,
min(case when actid = 5 then id end) as id5
from table t
group by trackid
) tlim
on t.id > tlim.id21 and t.id < tlim.id5
order by id;
This find the minimum id for each trackid
where the actid
is 21 and 5 and chooses the rows in-between.