The Problem here is the rinse cycle, as the wash cycle is only clean water, check that the rinse pipe that comes out of the m/c is not blocked or gunked up, as it may cause syphoning, i.e. sucking the dirty water back into the m/c which is what i suspect is happening.
Will Stirling, May 2009