Mishkat al-Masabih 766
Abu Sa'id al-Khudri said:
While God’s Messenger was leading his companions in prayer he took off his sandals and laid them at his left side; so when the people saw that, they removed their sandals. When he had finished his prayer he asked, "What made you remove your sandals? They replied, “We saw you remove yours, so we removed ours.” God’s Messenger then said, “Gabriel came to me and informed me that there was filth on them. When any of you comes to the mosque he should examine, and if he sees filth on his sandals he should wipe it off and pray in them.” 

Abu Dawud and Darimi transmitted it.
وَعَن أبي سعيد الْخُدْرِيّ قَالَ: بَيْنَمَا رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يُصَلِّي بِأَصْحَابِهِ إِذْ خلع نَعْلَيْه فَوَضَعَهُمَا عَنْ يَسَارِهِ فَلَمَّا رَأَى ذَلِكَ الْقَوْمُ أَلْقَوْا نِعَالَهُمْ فَلَمَّا قَضَى رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ صَلَاتَهُ قَالَ: «مَا حَمَلَكُمْ على إلقائكم نعالكم؟» قَالُوا: رَأَيْنَاك ألقيت نعليك فَأَلْقَيْنَا نِعَالَنَا. فَقَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «إِنْ جِبْرِيلَ أَتَانِي فَأَخْبَرَنِي أَنَّ فيهمَا قذرا إِذا جَاءَ أحدكُم إِلَى الْمَسْجِدَ فَلْيَنْظُرْ فَإِنْ رَأَى فِي نَعْلَيْهِ قَذَرًا أَو أَذَى فَلْيَمْسَحْهُ وَلِيُصَلِّ فِيهِمَا» . رَوَاهُ أَبُو دَاوُدَ وَالدَّارِمِيُّ