Time machines and traversable wormholes in modified theories of gravity