What is the origin of wearing black to funerals?

It is said to have originated from a time when people believed that when a loved one passed away, that the souls of the dead would leave that body any enter the body of a mourning loved one. So people started wearing black robes to hide their faces so that the lost soul would not find them and continue on to the after life. As years went by it transformed into a showing of respect for the dead.