One thing you could do that is potentially easier than rewinding a set amount of time is to rewind to the last time you grabbed a heart or died. Every time you die or grab a heart, you can save the positions and states of all of the ghosts, boxes, etc. The rewind goes back to the previous state. Just a thought. Hope it helps!