Averaging method for differential equations perturbed by dynamical systems