No you need to combine the two subdomains into one:
combined_subdomains = CellFunction("size_t", mesh, 0)
combined_subdomains.array()[subdomains.array()==24] = 1
combined_subdomains.array()[subdomains.array()==25] = 1
submesh = SubMesh(mesh, combined_subdomains, 1)
But it looks like a neat feature! Maybe you should consider implementing it and submit a pull request?