Complex Langevin dynamics for SU(3) gauge theory in the presence of a theta term