another approach is to use attachInterrupt : http://www.arduino.cc/en/Reference/AttachInterrupt
This calls a function on when a transition (on pin 2 or 3) is detected. In this function you can increment a count and check if the count is 4, if so you set your output pin high. If the count isn't 4 you set the pin low. This should give you the output you want.
What are you making?