Real-time filtering with sparse variations for head motion in magnetic resonance imaging