ok. if it's happening once reverse, once forward, and so on (as opposed to forward every time or reverse every time) then the cog is untightening, then tightening,then untightening,etc.
this is good as it means your threads probably arent stripped. Follow
these instructions, then come back here and give me reputation points: +ve if it fixes the problem, -ve if your bike catches fire :-)