by Juan Leyva.
You should:
First: core_enrol_get_users_courses for returning all the courses
Next: Get all the participants of that courses using the function: core_enrol_get_enrolled_users (passing as argument withcapability a capability your teachers must have)
And then iterate the courses/users and discard the courses where the user was not returned by the enrolled_users funciton