A teacher who groomed two girls he taught at a Melbourne school has been jailed and will be a registered sexual offender for life.