The “medium” and “large” are not custom image sizes – they are already part of the core WordPress media sizes and they should be handled via the “settings” -> “media” options page in wp-admin.
Give your custom image sizes a different and more unique name (reserved are thumbnail, medium, large, full)