The direct object takes the action of the verb. The indirect object takes something else from somewhere else. The best way is by illustrations. "He hit the ball to Sam." The ball was hit, not Sam. The ball took the action--hit--of the verb. Sam got something else--the ball.
She gave the gift to him. The gift was given. The gift took the action of the verb--to give. He got something else, not the action, but the gift itself.
So if you take out the prepositional phrases in the above examples you could just say "He hit Sam the ball" It still should be clear that one is the object of the verb and the other is not.
She gave him the gift. Still again, the gift took the action, right? He took the gift.
The direct object answers "what" or "whom" after the verb.
Emily brought cookies to the party.
Ms. S. taught history.
The indirect object tells "to whom" or "to what" after the verb. An indirect object comes between the verb and the direct object.
Emily brought the class cookies.
Ms. S. taught us history.