Sayyiduna Abdullah bin Zayd (may Allah be pleased with him) says that a complaint was made to the Prophet (peace and blessings be upon him) about a man who imagines something (passing wind) during prayer. He (peace and blessings be upon him) said: "He should not turn away from his prayer until he hears a sound or finds a smell."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 749