It could be a vacuum hose loose

. I had a problem last week with the engine speed occasionally (not all the time) dropping to about 400 rpm when in D or R which caused minor shaking of the car. When in N or P, the rpm's would rise to about 1500, drop to 500 and kept repeating this every couple of seconds on its own. I was changing some wires underhood over the weekend and found a couple of vacuum hoses had poped loose. I put them back where they belonged and no longer have the problem.