My Uno resets Your Uno - how to ground them?

It could also be a power issue or EM interferance.

But have you tried enabling the watchdog timer? You turn it on with a timeout up to 8 seconds, and have your code call the wdt_reset() function to reset the watchdog more frequently than that (typically like, every pass through loop). And if the code doesn't do that for long enough that the watchdog times out, it resets the board. It's meant as a solution for exactly this kind of problem.