An Invariance Principle for Martingales