It's based on prehispanic tradition.
When the death person goes on it's final travel to Chiconaumictlan (The longed place for the rest of the soul),
he (or she) has to cross Chiconahuapan (nine rivers or nine waters), the big river that surrounds the nine hells (To prehispanic mexicans, hell had not the same meaning that to us).
When the death person arrives to the edge of the river, he sees a lot of dogs at the other side, and...
if some of them recognizes him as his master, the dog then would help him to cross and make it safe to the other side.
Interesting, don't you think?
Best my friend!
René