TIMSK1=(1<<ICIE1)|(1<<TOIE1);
The code does not like having the overflow interrupt enabled without an overflow interrupt vector.
I don't see where you actually use the overflow interrupt vector, so you can change the line to just the input capture.
TIMSK1=(1<<ICIE1);
Alternatively, until you figure out what you want for the overflow vector just use a dummy
ISR (TIMER1_OVF_vect)
{
return;
}
Either course allows the program to avoid the resets.