Qays bin Talq narrates from his father, Sayyiduna Talq bin Ali (may Allah be pleased with him), that he asked the Prophet (peace and blessings be upon him), or someone else asked: I was praying, and meanwhile I began scratching my thigh, and my hand touched my private part. The Prophet (peace and blessings be upon him) said: "It is only a part of you." (b) The apparent state of one who scratches his thigh and whose hand touches his private part is that it touches it only with the back of the hand, and Allah knows best.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 647