Once you defeat the second boss, you have to go through the obstacles backwards to get back to your ship.