Your teacher's explanation mainly refers to verbs with the pattern "to <verb> <something> TO <someone>". In English the second "to" disappears when the person is named first, though (I write a letter to him = I write him a letter), so maybe that's why the different functions of the objects aren't always clear to an English speaker. In German you usually have the "to" object (mostly a person) in the dative case and the other in the accusative, so it's "ich schreibe ihm (dat.) einen Brief (acc.)". If you just swapped the cases, that would make as little sense as saying "I write him to a letter" in English.
Note, however, that there are also other verb patterns. "Helfen", for instance, only has a dative object, so you always have to say "ich helfe *dir*". You'll have to learn these by heart, and the same goes for the prepositions.