Objects are usually nouns — be it direct or indirect and a sentence generally presupposes direct object if there is an indirect object. So the common realisation of the object through noun phrase is replaced by the use of pronouns. To function as an object is a typical function of pronoun in objective case.
They see me (here 'me' is DO)
He is giving me my book (me here is IDO).
She gave (the girl) (a doll)—
To save this basic pattern (SVOO; here OOs are all nouns) from degenerating in total confusion, one of the objects is kept (noun / pronoun - it is a sin qua non) as direct object suffixed to the verb and indirect is distanced from the verb by the supplement of "to/for according to demand of the verb but retaining objective character.
One problematic area of personal pronoun in English is that unlike Spanish it substitutes both living and non-living. The sentence becomes a riddle. Let us take an example.
I teach 'my cat' (IDO) 'how to chuckle' (DO).
By substituting both the objects with "IT" we get this nonsensical sentence.
I teach it it.
Hence grammar says direct object is must/ distance IDO if need be/retain one of the objects as noun if possible because substitution (pronoun) can not surpass the original (noun). By the way, this is my own explanation scholars may find fault with.
Robert Frost rightly remarked, "A sentence is a sound in itself on which other sounds called words are stung"